package com.intellekt.ecert.domain;

import java.text.SimpleDateFormat;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;

@Results( { @Result(name = "forbidden", location = "forbidden.jsp") })
public abstract class DomainActionSupport extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = -6589104649941550869L;

    protected static SimpleDateFormat SDF_DDMMYYYY = new SimpleDateFormat("dd/MM/yyyy");
    protected static SimpleDateFormat SDF_DDMMYYYY_HHMMSS = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    
    private static final Logger log = Logger.getLogger(DomainActionSupport.class);

    @Autowired
    protected SecurityMap securityMap;

    public abstract String getActionId();

    public String verificar(String actionId, UsuarioVO user) {

        String menuid = securityMap.getMenuId(actionId);

        if (StringUtils.isBlank(menuid)) {
            throw new RuntimeException("El ActionId: " + actionId + " no existe en SecurityProperties (SecurityMap)");
        }

        if (log.isDebugEnabled()) {
            log.debug("ActionId: " + actionId);
            log.debug("menuid: " + menuid);
        }

        /*if (user.hasIdMenu(menuid) == false) {
            return "forbidden";
        } else {
            
        }*/
        return null;
    }

}
